#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "lsg_buddyfile.h"
#include "lsg_log.h"

using namespace LSG;

int main(int argc, char * argv[])
{
    if(argc != 2)
    {
	printf("test_buddyfile content\n");
	return -1;
    }

    lsg_set_log_path("./log");

    CBuddyFile buddyfile("./1024.8.0");

    if(buddyfile.Error()) {
	printf("init fail: %s\n", buddyfile.ErrMsg());
	return -1;
    }

    int buddybit_offset = buddyfile.Save(argv[1], strlen(argv[1]), 0);
    if(buddybit_offset < 0) {
	printf("Save fail: %d\n", buddybit_offset);
	return -1;
    }

    char *data = NULL;
    int data_len = 0;
    int e = buddyfile.Read(buddybit_offset, &data, &data_len, NULL);
    printf("Read %d: %s[%d]\n", buddybit_offset, data, e);

    return 0;
}
